#include <p24FJ32GA002.h>
#include <stdio.h>
#include <stdlib.h>

//_CONFIG1 ( 0x3F7F ) ;  	// NO JTAG 							0011111101111111 jtag en watchdogtimer functie  
//_CONFIG2 ( 0xF0DF );	// Fast RC Osc. 					1111000011011111 interne osc, geen pll=8mhz

#define _BV(bit) (1 << (bit))
#define bit_is_set(register,bit) (register & (1 << (bit)))
#define bit_is_clear(register,bit) (!(register & (1 << (bit)))) 

int main (void)
{
	unsigned long tijd1;
	unsigned char tijd2, buttons;
	char mysarray[]="$0106100000*JJ";
	InitLCD();
	InitTimer1();
	InitWireless();
	InitControls();
	tijd2=0;
	while(1)
	{
		tijd1=GetTime();
		while (1500 > GetTimeDifference(tijd1));
		if(ButtonChanged())
		{
			buttons=GetButtons();
			Line1();
			putsLCD("                ");
			Line1();
			//Int2LCD(buttons);
			//CHARACTER2LCD(',');
			//tijd2++;
			//Dec2LCD(tijd2);
			if(bit_is_set(buttons,1))
			{
				putsLCD("up,");
				mysarray[9]='1';
			}
			else
			{
				mysarray[9]='0';
			}
			if(bit_is_set(buttons,2))
			{
				putsLCD("down,");
				mysarray[10]='1';
			}
			else
			{
				mysarray[10]='0';
			}
			if(bit_is_set(buttons,3))
			{
				putsLCD("left,");
				mysarray[7]='1';
			}
			else
			{
				mysarray[7]='0';
			}
			if(bit_is_set(buttons,4))
			{
				putsLCD("right,");
				mysarray[8]='1';
			}
			else
			{
				mysarray[8]='0';
			}
		}
		putsU1(mysarray);
		PutU1enter();
	}
}
